package com.hapzxb.thread.synchronizede;

/**
 * 对于普通同步方法，锁是当前对象
 *
 * @Author: zhaoxb
 * @Date: 2019-04-09 21:36
 **/
public class Demo1Test {

    SynchronizedDemo1 x = new SynchronizedDemo1();
    SynchronizedDemo1 y = new SynchronizedDemo1();

    // 比较(01) x.isSyncA()与x.isSyncB()
    private void test1() {
        // 新建t11, t11会调用 x.isSyncA()
        Thread t11 = new Thread(() -> x.synMethodA(), "t11");

        // 新建t12, t12会调用 x.isSyncB()
        Thread t12 = new Thread(() -> x.synMethodB(), "t12");

        t11.start();  // 启动t11
        t12.start();  // 启动t12
    }

    public static void main(String[] args) {
        Demo1Test demo = new Demo1Test();
        demo.test1();
//		Thread name;t11 ,synMethodA....
//		Thread name;t11 ,synMethodA....
//		Thread name;t11 ,synMethodA....
//		Thread name;t11 ,synMethodA....
//		Thread name;t11 ,synMethodA....
//		Thread name;t12 ,synMethodB....
//		Thread name;t12 ,synMethodB....
//		Thread name;t12 ,synMethodB....
//		Thread name;t12 ,synMethodB....
//		Thread name;t12 ,synMethodB....
    }
}
